﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Telerik.Web.Mvc;
using Projectmanagement.Entity;
using ProjectManagement.Models;
using Projectmanagement.Utl;

namespace Projectmanagement.Controllers
{
    public class SimultaneousTeacherController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        [GridAction]
        public ActionResult _SelectIndex(int simultaneousid)
        {
            return View(new GridModel(DQ.GetSimultaneousTeacher(simultaneousid)));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _SaveAjaxEditing(int id, int simultaneousid)
        {
            var item = CH.DB.SimultaneousTeachers.Where(s => s.ID == id).Single();
            if (TryUpdateModel(item))
            {
                item.SimultaneousID = simultaneousid;
                CH.Edit<SimultaneousTeacher>(item);
            }
            return View(new GridModel(DQ.GetSimultaneousTeacher(simultaneousid)));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _InsertAjaxEditing(int simultaneousid)
        {
            var item = new SimultaneousTeacher();
            if (TryUpdateModel(item))
            {
                item.SimultaneousID = simultaneousid;
                CH.Create<SimultaneousTeacher>(item);
            }
            return View(new GridModel(DQ.GetSimultaneousTeacher(simultaneousid)));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _DeleteAjaxEditing(int id, int? simultaneousid)
        {
            CH.Delete<SimultaneousTeacher>(id);
            return View(new GridModel(DQ.GetSimultaneousTeacher(simultaneousid)));
        }
    }
}
